#include <stdio.h>
#include <stdlib.h>
struct Node 
{
 	int data;
 	struct Node *next;
};
struct Node *build();
struct Node *operate(struct Node *a,struct Node *b);
int main() 
{
 	struct Node *a,*b,*c;
 	a=build();
 	b=build();
 	c=operate(a,b);
 	if(!c)
  		printf("NULL\n");
 	while(c)
 	{
  		if(c->next==NULL)
   			printf("%d",c->data);
  		else
   			printf("%d ",c->data);
  		c=c->next;
 	} 
}
struct Node *build()
{
 	int a;
 	struct Node *head=NULL,*str=NULL;
 	scanf("%d",&a);
 	while(a!=-1)
 	{
  		struct Node *p=(struct Node*)malloc(sizeof(struct Node));
  		p->data=a;
  		p->next=NULL;
  		if(head==NULL)
   			head=p;
  		else
   			str->next=p;
  		str=p; 
  		scanf("%d",&a);
 	}
 	return head;
}
struct Node *operate(struct Node *a,struct Node *b)
{
 	struct Node *head=NULL,*str=NULL;
 	while(a&&b)
    	{
        	if((a->data)<(b->data))
           		a=a->next;
        	else if((a->data)>(b->data))
            		b=b->next;
        	else if((a->data)==(b->data))
        	{
         		if(head==NULL)
          			head=a;
         		else
          			str->next=a;
         		str=a;        
         		a=a->next;
         		b=b->next;
         		str->next=NULL;
  		}
 	}
 	return head;
}